package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.kennycason.kumo.WordFrequency;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DialogHistory;
import com.ruoyi.system.service.IDialogHistoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户问答历史Controller
 *
 * @author AousVolad
 * @date 2024-06-21
 */
@RestController
@RequestMapping("/dialoghistory/dialoghistory")
public class DialogHistoryController extends BaseController {
    @Autowired
    private IDialogHistoryService dialogHistoryService;

    /**
     * 查询用户问答历史列表
     */
    @PreAuthorize("@ss.hasPermi('dialoghistory:dialoghistory:list')")
    @GetMapping("/list")
    public TableDataInfo list(DialogHistory dialogHistory) {
        startPage();
        List<DialogHistory> list = dialogHistoryService.selectDialogHistoryList(dialogHistory);
        return getDataTable(list);
    }

    /**
     *  统计用户问题词频
     */
    @PreAuthorize("@ss.hasPermi('dialoghistory:dialoghistory:list')")
    @GetMapping("/wordCloud")
    public TableDataInfo wordCloud() {
        List<WordFrequency> list = dialogHistoryService.frequencyAnalyzer();
        return getDataTable(list);
    }

    /**
     * 导出用户问答历史列表
     */
    @PreAuthorize("@ss.hasPermi('dialoghistory:dialoghistory:export')")
    @Log(title = "用户问答历史", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DialogHistory dialogHistory) {
        List<DialogHistory> list = dialogHistoryService.selectDialogHistoryList(dialogHistory);
        ExcelUtil<DialogHistory> util = new ExcelUtil<DialogHistory>(DialogHistory.class);
        util.exportExcel(response, list, "用户问答历史数据");
    }

    /**
     * 获取用户问答历史详细信息
     */
    @PreAuthorize("@ss.hasPermi('dialoghistory:dialoghistory:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(dialogHistoryService.selectDialogHistoryById(id));
    }

    /**
     * 新增用户问答历史
     */
    @PreAuthorize("@ss.hasPermi('dialoghistory:dialoghistory:add')")
    @Log(title = "用户问答历史", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DialogHistory dialogHistory) {
        return toAjax(dialogHistoryService.insertDialogHistory(dialogHistory));
    }

    /**
     * GLM 接口
     */
    @PreAuthorize("@ss.hasPermi('dialoghistory:dialoghistory:add')")
    @Log(title = "用户问答历史", businessType = BusinessType.INSERT)
    @PostMapping("/glm")
    public AjaxResult glm(@RequestBody DialogHistory dialogHistory) {
        return success(dialogHistoryService.Glm(dialogHistory));
    }

    /**
     * 修改用户问答历史
     */
    @PreAuthorize("@ss.hasPermi('dialoghistory:dialoghistory:edit')")
    @Log(title = "用户问答历史", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DialogHistory dialogHistory) {
        return toAjax(dialogHistoryService.updateDialogHistory(dialogHistory));
    }

    /**
     * 删除用户问答历史
     */
    @PreAuthorize("@ss.hasPermi('dialoghistory:dialoghistory:remove')")
    @Log(title = "用户问答历史", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(dialogHistoryService.deleteDialogHistoryByIds(ids));
    }
}
